<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        width: 200px;
        height: 200px;
        background-color: pink;
      }
    </style>
  </head>
  <body>
    <div class="box">盒子</div>
    <input type="text" placeholder="请输入内容" />

    <script>
      const box = document.querySelector(".box");
      box.addEventListener("mouseenter", () => {
        console.log("鼠标进入盒子 mouseenter");
      });
      box.addEventListener("mouseleave", () => {
        console.log("鼠标离开盒子 mouseleave");
      });

      // 输入框事件
      const input = document.querySelector("input");
      // 获取和失去焦点事件
      input.addEventListener("focus", () => {
        console.log("输入框获取焦点 focus");
      });
      input.addEventListener("blur", () => {
        console.log("输入框失去焦点 blur");
      });
      // 键盘按下和抬起事件
      input.addEventListener("keydown", () => {
        console.log("输入框 keydown 按键按下 ");
      });
      input.addEventListener("keyup", (e) => {
        console.log("输入框 keyup 按键抬起 ", e.key);
        // 判断是否是回车键
        if (e.key === "Enter") {
          console.log("用户按下了回车");
        }
      });
      // 输入框 value 改变事件
      input.addEventListener("input", (e) => {
        console.log("输入框 input 输入内容", e.currentTarget.value);
      });
    </script>
  </body>
</html>
